package intant.enums.test;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class SelectEnumProTestCase {

    @Test
    public void testList() {
        Assertions.assertEquals(SelectEnum.list(ApplyStatus.class).size(), 5);
    }

    @Test
    public void testAsList() {
        Assertions.assertEquals(SelectEnum.asList(ApplyStatus.CREATED, ApplyStatus.NOT_PASSED).size(), 2);
        Assertions.assertEquals(SelectEnum.asList(ApplyStatus.DELETED, ApplyStatus.CREATED, ApplyStatus.NOT_PASSED).size(), 2);
    }

    /*
     * 示例：
     * 1、排除下拉项
     * 2、下拉项扩展属性
     */
    enum ApplyStatus implements SelectEnum<Integer> {
        DELETED(-1, "已删除") {
            @Override
            public SelectVo<Integer> getSelectVo() {
                // 将该项从默认列表中剔除
                return null;
            }
        },
        CREATED(1, "创建"),
        WAITING_AUDIT(2, "待审核"),
        PASSED(3, "已通过", true),
        NOT_PASSED(4, "未通过"),
        ARCHIVED(5, "已归档", true)
        ;

        private final Integer code;
        private final String desc;
        private final boolean checkedDef;

        ApplyStatus(Integer code, String desc) {
            this(code, desc, false);
        }

        ApplyStatus(Integer code, String desc, boolean checkedDef) {
            this.code = code;
            this.desc = desc;
            this.checkedDef = checkedDef;
        }

        @Override
        public Integer getCode() {
            return code;
        }

        @Override
        public String getDesc() {
            return desc;
        }

        public boolean isCheckedDef() {
            return checkedDef;
        }

        @Override
        public SelectVo<Integer> getSelectVo() {
            return new SelectVoPro(code, desc, checkedDef);
        }

        // 扩展默认的下拉vo, 添加属性
        public static class SelectVoPro extends SelectVo<Integer> {
            private boolean checkedDef;

            public SelectVoPro(Integer code, String desc, boolean checkedDef) {
                super(code, desc);
                this.checkedDef = checkedDef;
            }

            public boolean isCheckedDef() {
                return checkedDef;
            }

            @Override
            public String toString() {
                return "SelectVoPro{" +
                        "checkedDef=" + checkedDef +
                        "code='" + getCode() + '\'' +
                        ", desc='" + getDesc() + '\'' +
                        "} ";
            }
        }
    }

}
